package com.example.duanjunjie.learn.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.duanjunjie.learn.R;
import com.example.duanjunjie.learn.roundlayout.RoundActivity;
import com.example.duanjunjie.learn.utils.LogUtil;

/**
 * Created by duanjunjie on 2018/3/16.
 */

public class MyFragment extends Fragment {
    private static final String KEY_NAME="ARGS";
    public MyFragment() {
    }
    public static MyFragment newInstance(String agr){
        LogUtil.i("fragment"+agr+":newInstance");
        Bundle args=new Bundle();
        args.putString(KEY_NAME,agr);
        MyFragment myFragment=new MyFragment();
        myFragment.setArguments(args);
        return myFragment;
    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onCreate");
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onActivityCreated");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onCreateView");
        View view = inflater.inflate(R.layout.layout_fragment, container, false);
        TextView textView3 = view.findViewById(R.id.textView3);
        textView3.setText(getArguments().getString(KEY_NAME));
        if(getArguments().getString(KEY_NAME).equals("2")){
            textView3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getActivity().startActivity(new Intent(getActivity(), RoundActivity.class));
                }
            });
        }
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onViewCreated");
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onStart() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onStart");
        super.onStart();
    }

    @Override
    public void onResume() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onResume");
        super.onResume();
    }

    @Override
    public void onPause() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onPause");
        super.onPause();
    }

    @Override
    public void onStop() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onStop");
        super.onStop();
    }

    @Override
    public void onDestroyView() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onDestroyView");
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onDestroy");
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        LogUtil.i("fragment"+getArguments().getString(KEY_NAME)+":onDetach");
        super.onDetach();
    }

}
